package com.jtmg.glorykingsnews.api;


import com.github.pagehelper.PageInfo;
import com.jtmg.glorykingsnews.domain.TbManager;
import com.jtmg.glorykingsnews.service.TbManagerService;
import com.jtmg.glorykingsnews.vo.commom.LayuiReturnVo;
import com.jtmg.glorykingsnews.vo.commom.MsgVo;
import com.jtmg.glorykingsnews.vo.manager.ManagerQuery;
import com.jtmg.glorykingsnews.vo.manager.ManagerVo;
import com.jtmg.glorykingsnews.vo.manager.ManagerVoForQuery;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/manager/api/")
public class ManagerApi {

    @Resource
    private TbManagerService managerService;
    private JdbcTemplate jdbcTemplate;

    //超级管理员登录（账号和密码进行登录）
    @RequestMapping("loginSuper")
    public MsgVo loginSuper(@RequestBody ManagerVo vo) {
        return managerService.loginSuper(vo);
    }

    //管理员登录
    @PostMapping("loginManager")
    public String loginManamer(ManagerVo vo, HttpServletRequest request) {
        return managerService.loginManager(vo, request);
    }

    //该接口用于前端页面获取放在session的管理员信息
    @RequestMapping("getManagerInfo")
    public MsgVo<TbManager> getManagerInfo(HttpServletRequest request){
        HttpSession session = request.getSession();
        TbManager managerInfo = (TbManager) session.getAttribute("managerInfo");
        System.out.println(managerInfo);
        return new MsgVo<>("200","成功获取管理员登录信息",managerInfo);
    }

    //注册管理员(超级管理员来进行）
    @RequestMapping("registerManager")
    public MsgVo<TbManager> registerManager(ManagerVo vo) {
        return managerService.registerManager(vo);
    }

    //查询管理员（供超级管理员查询管理员信息）
    @RequestMapping("querymanager")
    public LayuiReturnVo<ManagerVoForQuery> pageList(ManagerQuery query){
        return managerService.queryManager(query);
    }

    //删除管理员（超级管理员来进行）
    @RequestMapping("deleteManager")
    public MsgVo deleteManager(String id){
        return managerService.deleteManager(id);
    }

}
